package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.OrderItem;
import com.situ.mall.mapper.OrderItemMapper;
import com.situ.mall.service.IOrderItemService;

@Service
public class OrderItemServiceImpl implements IOrderItemService {
	@Autowired
	private OrderItemMapper orderItemMapper;
	
	@Override
	public ServerResponse addOrderItem(OrderItem orderItem) {
		try {
			Integer count = orderItemMapper.insert(orderItem);
			if (count >= 1) {
				return ServerResponse.createSuccess("添加成功");
			} else {
				return ServerResponse.createError("添加失败");
			}
			
		} catch (Exception e) {
			return ServerResponse.createError("添加失败");
		}
	}

	@Override
	public List<OrderItem> selectOrderItem(Integer id) {
		return orderItemMapper.selectOrderItem(id);
	}


	//删除订单
	@Override
	public ServerResponse deleteOrderItem(Long orderNo) {
		try {
			Integer count = orderItemMapper.deleteByOrderNo(orderNo);
			if (count >= 1) {
				return ServerResponse.createSuccess("删除成功");
			} else {
				return ServerResponse.createError("删除失败");
			}
			
		} catch (Exception e) {
			return ServerResponse.createError("删除失败");
		}
	}

	//后台查询订单子页面
	@Override
	public List<OrderItem> selectOrderItem(Long orderNos) {
		return orderItemMapper.selectOrderItems(orderNos);
	}
}
